import { _decorator, AudioSource, Component, Node } from 'cc';
import { ResMgr } from './Managers/ResMgr';
import { StorageUtil } from './Utils/StorageUtil';
import { SoundMgr } from './Managers/SoundMgr';
import { TimeUtil } from './Utils/TimeUtil';
import { DisObjUtil } from './Utils/DisObjUtil';
import { SpriteUtil } from './Utils/SpriteUtil';
import { Utilitys } from './Utils/Utilitys';
import { PanelUtility } from './Utility/PanelUtility';
import { Game } from './Game/Game';
const { ccclass, property } = _decorator;

@ccclass('GameLaunch')
export class GameLaunch extends Component {
    //
    public static Instance: GameLaunch = null;

    @property(Node)
    public UIList:Node = null;

    @property(Node)
    public PopList:Node = null!;

    @property(AudioSource)
    public musicAudio:AudioSource;

    @property(AudioSource)
    public soundAudio:AudioSource;

    private forwardListeners:{[key:string]:{[key:string]:any[]}};//事件监听器

    onLoad(){
        if(null == GameLaunch.Instance){
            GameLaunch.Instance = this;
        }else{
            this.destroy();
            return;
        }

        //初始化游戏框架：资源管理、声音管理、UI管理、网络管理、日志管理
        this.node.addComponent(ResMgr);
        //end
        //初始化游戏模块
        this.node.addComponent(StorageUtil);
        this.node.addComponent(SoundMgr);
        this.node.addComponent(Game);
        this.node.addComponent(TimeUtil);
        this.node.addComponent(DisObjUtil);
        this.node.addComponent(PanelUtility);
        this.node.addComponent(SpriteUtil);
        this.node.addComponent(Utilitys);
    }

    start():void{
        //检测资源更新
        this.forwardListeners = {};
        //end
        console.log("GameLanch start");
        Game.Instance.StartGame();
    }
}

